/*
 * @Author: your name
 * @Date: 2021-06-07 13:51:37
 * @LastEditTime: 2021-06-07 13:58:20
 * @LastEditors: your name
 * @Description: In User Settings Edit
 * @FilePath: \bazai_ebook\vue.config.js
 */
const path = require('path')
// const CompressionPlugin = require('compression-webpack-plugin')
const resolve = dir => {
  return path.join(__dirname, dir)
}
function mock (app, url, data) {
  app.get(url, (req, res) => {
    res.json(data)
  })
}

const homeData = require('./src/mock/bookHome')
const shelfData = require('./src/mock/bookShelf')
const listData = require('./src/mock/bookList')
const flatListData = require('./src/mock/bookFlatList')

module.exports = {
  chainWebpack: config => {
    config.resolve.alias
    .set('@', resolve('src'))
    .set('_c', resolve('src/components'))
  },
  css: {
    loaderOptions: {
      sass: {
        prependData: `@import '@/assets/styles/global.scss';`
      }
    }
  },
  devServer: {
    before (app) {
      mock(app, '/book/home', homeData)
      mock(app, '/book/shelf', shelfData)
      mock(app, '/book/list', listData)
      mock(app, '/book/flat-list', flatListData)
    }
  }
  // devServer: {
  //   port: 8080,
  //   proxy: { // 配置跨域
  //     '/epub': {
  //       target: 'http://81.71.93.230:8081/epub', // 这里后台的地址模拟的;应该填写你们真实的后台接口
  //       ws: true,
  //       changOrigin: true, // 允许跨域
  //       pathRewrite: {
  //         '^/epub': 'epub' // 请求的时候使用这个api就可以
  //       }
  //     }
  //   }
  // }
  // configureWebpack: {
  //   plugins: [
  //     new CompressionPlugin({
  //       test: /\.(js|css|png|jpg)?$/i, // 哪些文件要压缩
  //       filename: '[path].gz[query]', // 压缩后的文件名
  //       algorithm: 'gzip', // 使用gzip压缩
  //       minRatio: 0.8, // 压缩率小于1才会压缩
  //       deleteOriginalAssets: false// 删除未压缩的文件，谨慎设置，如果希望提供非gzip的资源，可不设置或者设置为false
  //     })
  //   ]
  // }
}